#include "ivssetting.h"

IVSSetting::IVSSetting()
{
    verboseLevel = 0;
}

int IVSSetting::readIVSIniFile()
{
    QSettings settings(IVS_SETTING_FILE, QSettings::IniFormat);
    if(settings.status() == QSettings::NoError){
        verboseLevel = settings.value("Verbose level", 0).toInt();

        settings.beginGroup("Video player settings");
        video_player_settings.isEnableROI = settings.value("Enable ROI", false).toBool();
        settings.endGroup();

        settings.beginGroup("Intruders detection settings");
        intruders_detection_settings.noFrameToInitBackground = settings.value("Init BG(#frame)", 10).toInt();
        intruders_detection_settings.alpha = settings.value("Alpha", 0.02).toFloat();
        intruders_detection_settings.stateChangeDelay = settings.value("State change delay(#frame)", 500).toInt();
        intruders_detection_settings.bnRectArea_min = settings.value("Bound rect area(min)", 600).toUInt();
        intruders_detection_settings.bnRectArea_max = settings.value("Bound rect area(max)", 6000).toUInt();
        intruders_detection_settings.noBin = settings.value("Number of bin", 16).toInt();
        settings.endGroup();

        settings.beginGroup("Restricted area survuillance settings");
        restricted_area_survuillance_settings.noFrameToInitBackground = settings.value("Init BG(#frame)", 10).toInt();
        restricted_area_survuillance_settings.alpha = settings.value("Alpha", 0.02).toFloat();
        restricted_area_survuillance_settings.stateChangeDelay = settings.value("State change delay(#frame)", 500).toInt();
        restricted_area_survuillance_settings.bnRectArea_min = settings.value("Bound rect area(min)", 600).toUInt();
        restricted_area_survuillance_settings.bnRectArea_max = settings.value("Bound rect area(max)", 6000).toUInt();
        restricted_area_survuillance_settings.noBin = settings.value("Number of bin", 16).toInt();
        settings.endGroup();

        settings.beginGroup("Fence survuillance settings");

        settings.endGroup();

        settings.beginGroup("People counting settings");
        // = settings.value("", ).toString();
        settings.endGroup();

        settings.beginGroup("People tracking settings");
        // = settings.value("", ).toString();
        settings.endGroup();

        settings.beginGroup("Theft detection settings");
        // = settings.value("", ).toString();
        settings.endGroup();

        settings.beginGroup("Object left behide detection settings");
        // = settings.value("", ).toString();
        settings.endGroup();

        settings.beginGroup("Camera checks settings");
        camera_checks_settings.noFrameToInitBackground = settings.value("Init BG(#frame)",10 ).toInt();
        camera_checks_settings.alpha = settings.value("Alpha", 0.1).toFloat();
        camera_checks_settings.stateChangeDelay = settings.value("State change delay(#frame)", 200).toInt();
        camera_checks_settings.videoPlaySpeedBoost = settings.value("Video play speed boost(fps)", 0).toInt();
        camera_checks_settings.beCoveredThreshold = settings.value("Be covered threshold(illumination)", 60).toInt();
        settings.endGroup();


        // = settings.value("", ).toString();

        return 0;
    }else
        return -1; // access error or malformat
}

int IVSSetting::writeIVSIniFile()
{
    QSettings settings(IVS_SETTING_FILE, QSettings::IniFormat);
    if(settings.status() == QSettings::NoError){
        settings.setValue("Verbose level", verboseLevel);

        settings.beginGroup("Video player settings");
        settings.setValue("Enable ROI",video_player_settings.isEnableROI);
        settings.endGroup();

        settings.beginGroup("Intruders detection settings");
        settings.setValue("Init BG(#frame)",intruders_detection_settings.noFrameToInitBackground);
        settings.setValue("Alpha",intruders_detection_settings.alpha);
        settings.setValue("State change delay(#frame)",intruders_detection_settings.stateChangeDelay);
        settings.setValue("Bound rect area(min)",intruders_detection_settings.bnRectArea_min);
        settings.setValue("Bound rect area(max)",intruders_detection_settings.bnRectArea_max);
        settings.setValue("Number of bin", intruders_detection_settings.noBin);
        settings.endGroup();

        settings.beginGroup("Restricted area survuillance settings");
        settings.setValue("Init BG(#frame)",restricted_area_survuillance_settings.noFrameToInitBackground);
        settings.setValue("Alpha",restricted_area_survuillance_settings.alpha);
        settings.setValue("State change delay(#frame)",restricted_area_survuillance_settings.stateChangeDelay);
        settings.setValue("Bound rect area(min)",restricted_area_survuillance_settings.bnRectArea_min);
        settings.setValue("Bound rect area(max)",restricted_area_survuillance_settings.bnRectArea_max);
        settings.setValue("Number of bin", restricted_area_survuillance_settings.noBin);
        settings.endGroup();

        settings.beginGroup("Fence survuillance settings");
        //settings.setValue("",);
        settings.endGroup();

        settings.beginGroup("People counting settings");
        //settings.setValue("",);
        settings.endGroup();

        settings.beginGroup("People tracking settings");
        //settings.setValue("",);
        settings.endGroup();

        settings.beginGroup("Theft detection settings");
        //settings.setValue("",);
        settings.endGroup();

        settings.beginGroup("Object left behide detection settings");
        //settings.setValue("",);
        settings.endGroup();

        settings.beginGroup("Camera checks settings");
        settings.setValue("Init BG(#frame)",camera_checks_settings.noFrameToInitBackground);
        settings.setValue("Alpha",camera_checks_settings.alpha);
        settings.setValue("State change delay(#frame)",camera_checks_settings.stateChangeDelay);
        settings.setValue("Be covered threshold(illumination)",camera_checks_settings.beCoveredThreshold);
        settings.setValue("Video play speed boost(fps)",camera_checks_settings.videoPlaySpeedBoost);
        settings.endGroup();
    }else
        return -1;

    return 0;
}

int IVSSetting::VerboseLevel()
{
    return verboseLevel;
}
